package cn.lan.generator;

import cn.lan.generator.bean.Connector;
import cn.lan.generator.bean.ProjInfo;
import cn.lan.generator.bean.TableEntity;
import cn.lan.generator.factory.ProjectManagerFactory;
import cn.lan.generator.manager.AbstractProjectManager;
import cn.lan.generator.utils.Constant;

/**
 * @author lanping
 * @version 1.0
 * @date 2019-07-14
 **/
public class GeneratorExample {

    public static void main(String[] args) {
        ProjInfo projInfo = new ProjInfo();
        //开发者
        projInfo.setAuthor("lanping");
        projInfo.setAuthorEmail("lan.ping@daikin.net.cn");
        //包名
        projInfo.setPackageName("cn.lanping");
        //后端项目名称
        projInfo.setProjectName("springboot-generator-web");
        //后端项目简称
        projInfo.setProjectSimpleName("generator");
        //业务模块名称
        projInfo.setModuleName("core");
        //是否生成前端页面代码 默认false
        projInfo.setThymeleaf(false);
        //前台显示项目名称
        projInfo.setProjectSysName("Springboot Code Generator");
        //项目端口
        projInfo.setPort(9999);
        //默认调试模式 为true时 模板文件路径为项目目录的target下，false时 模板文件路径为templateDir
        projInfo.setDebugModel(true);
        
        //createModulePomXml 初次创建需要设置成true，再次生成其他表业务时设置为false
        projInfo.setCreateModulePomXml(true);

        projInfo.setAccessBaseUrl("/v1/op/");

        Connector connector = new Connector();
        //数据库类型 默认mysql
        connector.setDbType(Constant.DB_TYPE_MYSQL);
        connector.setDriver("com.mysql.cj.jdbc.Driver");
        connector.setUrl("jdbc:mysql://127.0.0.1:3306/springboot_demo?useUnicode=true&useSSL=false&characterEncoding=utf-8&serverTimezone=UTC&allowPublicKeyRetrieval=true");
        connector.setUser("root");
        connector.setPassword("root123456");

        try {
            AbstractProjectManager projectManager = ProjectManagerFactory.getProjectManager(connector.getDbType());

            //生成空业务的项目
//            projectManager.createFilesEmptyBusiness(connector,projInfo);

            //单表或多表
//            TableEntity tableEntity = new TableEntity();
//            tableEntity.setTableNames("sys_user","sys_role");
//            projectManager.createFilesByTables(connector, projInfo, tableEntity);

            //生成全部
            projectManager.createFiles(connector, projInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
